/*================================================================
*   Copyright (C) 2020 Sangfor Ltd. All rights reserved.
*   
*   文件名称：test.c
*   创 建 者：Ann
*   创建日期：2020年04月26日
*   描    述：
*
================================================================*/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
    extern char** environ;
    printf("我是test可执行程序\n");
    for(int i = 0; environ[i]; i++)
    {
        printf("%s\n", environ[i]);
        printf("\n");
    }
    printf("我是test可执行程序，打印完毕环境变量了\n");
    for(int i = 0; i < argc; i++)
    {
        printf("pram[%d] : %s\n", i, argv[i]);
    }
    printf("我是test可执行程序，打印完毕命令行参数了\n");
    sleep(5);
    /*-----------exec l系列函数-----------------*/
    //execl("./myexec", "exec", "-l", NULL);
    //execlp("/home/wudu/work/linux/linux-68/linux-lesson11/myexec", "myexec", "-l", NULL);
    //char* envp[] = {"MYENV=xxxx", "HEHE=yyyy", NULL};

    //execle("/home/wudu/work/linux/linux-68/linux-lesson11/myexec", "myexec", "-l", NULL, envp);

    /*-----------exec v系列函数-----------------*/
    char* const argv1[] = {"myexec", "-l","-hello", "-123456789", NULL};
    
    //execv("/home/wudu/work/linux/linux-68/linux-lesson11/myexec", argv1); 
    //execv("myexec", argv1); 
    execve("myexec", argv1, environ); 
    perror("execl");
    printf("hehehh\n");
    exit(-1);
    return 0;
}
